package com.example.mapper.aboutUser;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.pojo.aboutUser.SystemRole;
import com.example.pojo.aboutUser.User;
import com.example.pojo.aboutUser.UserRoleRelation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserRoleRelationMapper extends BaseMapper<UserRoleRelation> {

    // 获取用户的所有角色
    @Select("SELECT r.* FROM user u JOIN user_role_relation ur ON u.id = ur.user_id JOIN system_role r ON ur.role_id = r.id WHERE u.id = #{userId} and r.role_state = true and r.is_delete = false")
    List<SystemRole> getRolesByUserId(Integer userId);


    // 获取指定角色ID的所有用户
    @Select("SELECT u.* FROM user u JOIN user_role_relation ur ON u.id = ur.user_id WHERE ur.role_id = #{roleId}")
    List<User> getUsersByRoleId(Integer roleId);

}
